<template>
  <el-header class="l-content">
    <div class="l-content">
      <!-- 图标展示 -->
      <el-button size="small" plain @click="handleCollapse">
        <el-icon :size="20">
          <Menu />
        </el-icon>
      </el-button>

      <el-breadcrumb separator="/" class="bread">
      <!-- 首页一定存在，写死 -->
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="current.path" v-if="current">{{current.label}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown>
        <span class="el-dropdown-link">
          <img class="user" :src="getImageUrl('user')" alt="" />
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item @click="handleLoginout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </el-header>
</template>

<script>
import { useStore } from 'vuex';
import { computed } from 'vue';
import { useRouter } from 'vue-router';
export default {
  setup() {
    let store = useStore();
    //  const imgSrc = require('../assets/images/user.png')
    let getImageUrl = (user) => {
      return new URL(`../assets/images/${user}.png`, import.meta.url).href;
    };
    let handleCollapse = () => {
      store.commit('updateIsCollapse');
    };
    //计算属性
    const  current = computed(()=>{
      return store.state.currentMenu;
    })
    //退出
    const router = useRouter();
    const handleLoginout =()=>{
      store.commit("cleanMenu")
      router.push({
        name:'login',
      })
    }
    return {
      getImageUrl,
      handleCollapse,
      current,
      handleLoginout
    };
  },
};
</script>

<style lang="less" scoped>
:deep(:focus) {
  outline: 0;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: #333;
}
.r-content {
  .user {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}
.l-content {
  display: flex;
  align-content: center;
  align-items: center;
  .el-button {
    margin-right: 20px;
  }
  h3 {
    font-size: 18px;
    color: #fff;
  }
}
// .bread /deep/ span{
//   color:#fff !important;
//   cursor: pointer !important;
// }
:deep(.bread span){
  color:#fff !important;
  cursor: pointer !important;
}
</style>
